<?php

function smarty_function_getcategory_by_topic_id($params, &$smarty) {
    //Get value from page
    $id = $params['topic_id'];
    if($id){
      //Query data

    $pntables = pnDBGetTables();
    $tpc_table  = $pntables['innoforum_topics'];
    $cty_table  = $pntables['innoforum_category'];
    $scy_table  = $pntables['innoforum_subcategory'];
    $tpc_column = $pntables['innoforum_topics_column'];
    $cty_column = $pntables['innoforum_category_column'];
    $scy_column = $pntables['innoforum_subcategory_column'];

      $sql = "SELECT
                $tpc_table.$tpc_column[category_id] as category_id,
                $cty_table.$cty_column[name] as category_name,
                $scy_table.$scy_column[id] as subcategory_id,
                $scy_table.$scy_column[name] as subcategory_name
              FROM 
                $tpc_table ,
                $cty_table,
                $scy_table
              WHERE
                $tpc_table.$tpc_column[id] = $id
              AND
                $cty_table.$cty_column[id] = $tpc_table.$tpc_column[category_id]
              AND
                $scy_table.$scy_column[id] = $tpc_table.$tpc_column[subcategory_id]";

      $column = array("category_id","category_name","subcategory_id","subcategory_name");
      $result = DBUtil::executeSQL($sql);
      $objectArray = DBUtil::marshallObjects ($result, $column);
      //$category = $objectArray['0']['category_name'];
      //$subcategory = $objectArray['0']['subcategory_name'];
      $smarty->assign("category_id", $objectArray['0']['category_id']);
      $smarty->assign("subcategory_id", $objectArray['0']['subcategory_id']);
      $smarty->assign("category", $objectArray['0']['category_name']);
      $smarty->assign("subcategory", $objectArray['0']['subcategory_name']);
    }


}